include config

#############################
# execution file name
#############################
RESULT			= tetris

##############################
# MUST define root dir!!!
##############################
ROOT_DIR = ..

##############################
# toolchain defines.
##############################
CC			= gcc
SHELL			= sh
SED			= sed
RM			= rm

DEPOPT			= -MM
INCLUDES		+= -I$(ROOT_DIR)/include
LINKPATH		+= $(ROOT_DIR)/lib
LDFLAGS			+= -static -lsm

##############################
# Objects to Build.
##############################
SOURCES := $(wildcard *.c)
DEPFILES := $(patsubst %.c, .%.d, $(SOURCES))
OBJS := $(patsubst %.c, %.o, $(SOURCES))

.PHONY: all clean tags

all: $(OBJS)
	$(CC) -o $(RESULT) $(OBJS) -L$(LINKPATH) $(LDFLAGS)
	@echo program is ready to go. :P

include $(DEPFILES)

%.o: %.c
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

.%.d: %.c
	@$(SHELL) -ec '$(CC) $(DEPOPT) $(CFLAGS) $(INCLUDES) $< \
	| $(SED) '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
	[ -s $@ ] || $(RM) $@'

##############################
# Clean up.
##############################	
clean:
	@rm -f $(OBJS) $(DEPFILES) $(RESULT)
	@echo remove all output files
tags:
	@ctags -R *
	@echo tags is made
